<div id="mod_output_{{each_output.unique_id}}">
  <form id="mod_output_form" method="post" action="/output">
  {{form_mod_output.csrf_token}}
  {{form_mod_output.output_id(class_='form-control', value=each_output.unique_id)}}
  {{form_mod_output.output_pin(class_='form-control', value=each_output.pin)}}

  {% set form = form_mod_output %}
  {% set dict_options = dict_outputs[each_output.output_type] %}
  {% set each_device = each_output %}
  {% set unique_id = each_output.unique_id %}

    <div class="row small-gutters">
      <div class="col-auto">
        <button type="button" class="form-control btn btn-primary btn-sm btn-block" data-dismiss="modal">{{_('Close')}}</button>
      </div>
      <div class="col-auto">
        <input onclick="return $(this).processRequest(this, 'output_mod');" name="output_mod" value="{{_('Save')}}" class="form-control btn btn-primary btn-sm btn-block" type="button"/>
      </div>
      <div class="col-auto">
        <input onclick="return confirm('{{_('Are you sure you want to delete this?')}}') && $(this).processRequest(this, 'output_delete');" name="output_delete" value="{{_('Delete')}}" class="form-control btn btn-primary btn-sm btn-block" type="button"/>
      </div>
    </div>

    <div class="row small-gutters" style="padding: 0.5em">

      {% if 'output_manufacturer' in dict_outputs[each_output.output_type] %}
      <div class="col-12">
        {{_("Manufacturer")}}: {{dict_outputs[each_output.output_type]['output_manufacturer']}}
      </div>
      {% endif %}

  {% if 'dependencies_module' in dict_outputs[each_output.output_type] and dict_outputs[each_output.output_type]['dependencies_module'] %}
      <div class="col-12">
    {{_("Library")}}:
    {% for each_lib in dict_outputs[each_output.output_type]['dependencies_module'] -%}
      {%- if each_lib[0] == 'pip-pypi' -%}
        {%- if "==" in each_lib[2] -%}
      <a href="https://pypi.org/project/{{each_lib[2].split('==')[0]}}/{{each_lib[2].split('==')[1]}}" target="_blank">{{each_lib[2].split('==')[0]}}</a>
        {%- else -%}
      <a href="https://pypi.org/project/{{each_lib[2]}}" target="_blank">{{each_lib[2]}}</a>
        {%- endif -%}
      {%- else -%}
        {{each_lib[1]}}
      {%- endif -%}
      {%- if not loop.last %}, {% endif %}
    {% endfor %}
      </div>
  {% endif %}

  {% set manufacturer_url = 'url_manufacturer' in dict_outputs[each_output.output_type] and dict_outputs[each_output.output_type]['url_manufacturer'] %}
  {% set datasheet_url = 'url_datasheet' in dict_outputs[each_output.output_type] and dict_outputs[each_output.output_type]['url_datasheet'] %}
  {% set product_purchase_url = 'url_product_purchase' in dict_outputs[each_output.output_type] and dict_outputs[each_output.output_type]['url_product_purchase'] %}
  {% set additional_url = 'url_additional' in dict_outputs[each_output.output_type] and dict_outputs[each_output.output_type]['url_additional'] %}

  {% if manufacturer_url or datasheet_url or product_purchase_url or additional_url %}
      <div class="col-12">
    {{_('Literature') + ': '}}
  {%- if manufacturer_url -%}
    {{_("Manufacturer")}} {% for each_url in dict_outputs[each_output.output_type]['url_manufacturer'] %}<a href="{{each_url}}" target="_blank">Link {{loop.index}}</a>{{ ", " if not loop.last }}{% endfor %}
  {%- endif -%}
  {%- if datasheet_url -%}
    {% if manufacturer_url %}; {% endif -%}
    {{_("Datasheet")}} {% for each_url in dict_outputs[each_output.output_type]['url_datasheet'] %}<a href="{{each_url}}" target="_blank">Link {{loop.index}}</a>{{ ", " if not loop.last }}{% endfor %}
  {%- endif -%}
  {%- if product_purchase_url -%}
    {% if manufacturer_url or datasheet_url %}; {% endif -%}
    {{_("Product")}} {% for each_url in dict_outputs[each_output.output_type]['url_product_purchase'] %}<a href="{{each_url}}" target="_blank">Link {{loop.index}}</a>{{ ", " if not loop.last }}{% endfor %}
  {%- endif -%}
  {%- if additional_url -%}
    {% if manufacturer_url or datasheet_url or product_purchase_url %}; {% endif -%}
    {{_("Additional")}} {% for each_url in dict_outputs[each_output.output_type]['url_additional'] %}<a href="{{each_url}}" target="_blank">Link {{loop.index}}</a>{{ ", " if not loop.last }}{% endfor %}
  {%- endif -%}.
      </div>
  {% endif %}

  {% if 'message' in dict_outputs[each_output.output_type] %}
      <div class="col-12" style="padding-top: 0.3em">
        {{dict_outputs[each_output.output_type]['message']|safe}}
      </div>
  {% endif %}

      <div id="return_text_{{each_output.unique_id}}" class="col-12"></div>

    </div>

  {% if each_output.output_type in custom_commands and custom_commands[each_output.output_type] %}
    {% set force_default_value = true %}
    {% set custom_options_values = none %}
    <div class="row small-gutters align-items-end" style="padding: 0.5em">
      <div class="col-12">
        <h5>{{_('Commands')}}</h5>
      </div>
      {% include 'pages/form_options/Custom_Actions_Message.html' %}
      {% if 'custom_commands' in dict_options %}
        {% for each_option in dict_options['custom_commands'] %}
          {% include 'pages/form_options/Custom_Options.html' %}
        {% endfor %}
      {% endif %}
    </div>
  {% endif %}

    <div class="row small-gutters" style="padding: 0.5em">
      <div class="col-12">
        <h5>{{_('Options')}}</h5>
      </div>

      <div class="col-auto">
        {{form_mod_output.name.label(class_='control-label')}}
        <div>
          {{form_mod_output.name(class_='form-control', value=each_output.name, **{'title': dict_translation['name']['phrase']})}}
        </div>
      </div>

  {% if each_output.output_type != 'output_spacer' %}

      <div class="col-auto">
        {{form_mod_output.log_level_debug.label(class_='control-label')}}
        <div class="input-group-text">
          <input id="log_level_debug" name="log_level_debug" type="checkbox" value="y"{% if each_output.log_level_debug %} checked{% endif %}>
        </div>
      </div>

{% include 'pages/form_options/Interface.html' %}
{% include 'pages/form_options/GPIO.html' %}
{% include 'pages/form_options/GPIO_Pin.html' %}
{% include 'pages/form_options/Bluetooth.html' %}
{% include 'pages/form_options/I2C.html' %}
{% include 'pages/form_options/FTDI.html' %}
{% include 'pages/form_options/UART.html' %}
{% include 'pages/form_options/Baud_Rate.html' %}
{% include 'pages/form_options/Location.html' %}
{% include 'pages/form_options/Period.html' %}

  {% endif %}
    </div>

  {% set custom_options_values = custom_options_values_outputs %}

  {% if ('custom_options' in dict_options and custom_options_values[unique_id]) or
        'custom_options_message' in dict_options %}
    {% set force_default_value = true %}
    <div class="row small-gutters" style="padding: 0.5em">
      <div class="col-12">
        <h5>{{_('Custom Options')}}</h5>
      </div>
    {% if 'custom_options_message' in dict_options %}
      {% include 'pages/form_options/Custom_Options_Message.html' %}
    {% endif %}
    {% if 'custom_options' in dict_options %}
      {% for each_option in dict_options['custom_options'] %}
        {% include 'pages/form_options/Custom_Options.html' %}
      {% endfor %}
    {% endif %}
    </div>
  {% endif %}

  {% set output_channel = output_channel.query.filter(output_channel.output_id == each_output.unique_id).all() %}

  {%- set output_channel_exists = [] -%}
  {% for each_output_channel in output_channel %}
    {%- do output_channel_exists.append(1) -%}
  {% endfor %}

  {% if output_channel_exists %}

    <div class="row small-gutters" style="padding: 1em 0 0 0.5em">
      <div class="col-12">
        <h5>{{_('Channel Options')}}</h5>
      </div>
    </div>

  {% endif %}

  {% set custom_options_values = custom_options_values_output_channels %}
  {% set dict_options = dict_outputs[each_output.output_type] %}
  {% set unique_id = each_output.unique_id %}
  {% set each_device = each_output %}
  {% set force_default_value = true %}
  {% set channel_options = true %}

  {% for each_output_channel in output_channel %}

    {% set channel = each_output_channel.channel %}
    {% set name_prefix = each_device.unique_id + "_" + channel|string + "_" %}

    {% if output_channel|length > 1 %}
    <hr/>
    <div class="row">
      <div class="col-auto">
        Channel {{channel}}

      {%- if 'name' in custom_options_values[each_output.unique_id][channel] and
           custom_options_values[each_output.unique_id][channel]['name'] -%}
        {{': ' + custom_options_values[each_output.unique_id][channel]['name']}}
      {%- elif 'name' in dict_outputs[each_output.output_type]['channels_dict'][channel] -%}
        {{': ' + dict_outputs[each_output.output_type]['channels_dict'][channel]['name']}}
      {%- endif -%}
      </div>
    </div>
    {% endif %}

        {% if custom_options_values[unique_id] %}

          {% if 'custom_channel_options_message' in dict_options %}
      <div class="row small-gutters" style="padding: 0.5em">
          <div class="col-12" style="padding-bottom: 0.5em">
            {{dict_options['custom_channel_options_message']|safe}}
          </div>
      </div>
          {% endif %}

          {% if 'custom_channel_options' in dict_options %}
      <div class="row small-gutters" style="padding: 0.5em">
            {% for each_option in dict_options['custom_channel_options'] %}
              {% include 'pages/form_options/Custom_Options.html' %}
            {% endfor %}
      </div>
          {% endif %}
        {% endif %}

    {% if 'button_send_duration' in dict_options['options_enabled'] or
          'button_send_value' in dict_options['options_enabled'] or
          'button_send_volume' in dict_options['options_enabled'] or
          'button_send_duty_cycle' in dict_options['options_enabled']  %}

    <div class="row align-items-end small-gutters" style="padding: 0.5em 0 0.5em 1.0em">

      {% if 'button_send_duration' in dict_options['options_enabled'] %}

      <div class="col-auto">
        <label class='form-check-label'>{{dict_translation['output_amount_duration']['title']}}</label>
        <div>
          <input class="form-control" name="on_seconds_{{each_output.unique_id}}_{{each_output_channel.unique_id}}" title="{{dict_translation['output_amount_duration']['phrase']}}" type="text" value="">
        </div>
      </div>
      <div class="col-auto">
        <input onclick="return $(this).output_on_amt(this, '{{each_output.unique_id}}', '{{each_output_channel.unique_id}}', 'seconds');" class="btn btn-success btn-block output_on_amt" id="turn_on" name="{{each_output.unique_id}}/{{each_output_channel.unique_id}}/on/sec/" type="button" value="{{_('Send')}}">
      </div>

      {% endif %}

      {% if 'button_send_value' in dict_options['options_enabled'] %}

      <div class="col-auto">
        <label class='form-check-label'>{{dict_translation['output_amount_value']['title']}}</label>
        <div>
          <input class="form-control" name="on_value_{{each_output.unique_id}}_{{each_output_channel.unique_id}}" title="{{dict_translation['output_amount_value']['phrase']}}" type="text" value="">
        </div>
      </div>
      <div class="col-auto">
        <input onclick="return $(this).output_on_amt(this, '{{each_output.unique_id}}', '{{each_output_channel.unique_id}}', 'value');" class="btn btn-success btn-block output_on_amt" name="{{each_output.unique_id}}/{{each_output_channel.unique_id}}/on/value/" type="button" value="{{_('Send')}}">
      </div>

      {% endif %}

      {% if 'button_send_volume' in dict_options['options_enabled'] %}

      <div class="col-auto">
        <label class='form-check-label'>{{dict_translation['output_amount_volume']['title']}}</label>
        <div>
          <input class="form-control" name="on_volume_{{each_output.unique_id}}_{{each_output_channel.unique_id}}" title="{{dict_translation['output_amount_volume']['phrase']}}" type="text" value="">
        </div>
      </div>
      <div class="col-auto">
        <input onclick="return $(this).output_on_amt(this, '{{each_output.unique_id}}', '{{each_output_channel.unique_id}}', 'volume');" class="btn btn-success btn-block output_on_amt" name="{{each_output.unique_id}}/{{each_output_channel.unique_id}}/on/vol/" type="button" value="{{_('Send')}}">
      </div>

      {% endif %}

      {% if 'button_send_duty_cycle' in dict_options['options_enabled'] %}

      <div class="col-auto">
        <label class='form-check-label'>{{dict_translation['duty_cycle']['title']}}</label>
        <div>
          <input class="form-control" name="on_duty_cycle_{{each_output.unique_id}}_{{each_output_channel.unique_id}}" title="{{dict_translation['duty_cycle']['phrase']}}" type="number" value="">
        </div>
      </div>
      <div class="col-auto">
        <input onclick="return $(this).output_on_amt(this, '{{each_output.unique_id}}', '{{each_output_channel.unique_id}}', 'pwm');" class="btn btn-success btn-block output_on_amt" name="{{each_output.unique_id}}/{{each_output_channel.unique_id}}/on/pwm/" type="button" value="{{_('Send')}}">
      </div>

      {% endif %}

    </div>

    {% endif %}
  {% endfor %}

  </form>
</div>
